<div class="col-xs-12 info-center">
    <ol class="breadcrumb" >
        <li> <i class="fa fa-anchor"></i>
            &nbsp;用户设置
        </li>
        <li>管理员列表</li>
    </ol>
    <div class="bs-callout bs-callout-warning">
        <h4>
            系统使用单位: <strong>{:C('MANUFACTURER')}</strong>
        </h4>
    </div>
</div>

<div class="col-xs-12 info-center">

    <div class="panel panel-mcit">

        <div class="panel-heading" > <i class="fa fa-list"></i>
            &nbsp;&nbsp;用户列表 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
            <a href="__URL__/addUser" style="color: #ffffff"><i class="glyphicon glyphicon-user"></i>&nbsp;&nbsp;<b>添加用户</b></a>

        </div>
        <table class="table table-bordered table-striped table-mcit">
            <thead>
                <tr>
                    <th width="5%">
                        <a class='btn btn-block btn-mcit' disabled>ID</a>
                    </th>
                    <th>
                        <a class='btn btn-block btn-mcit' disabled>账号</a>
                    </th>
                    <th>
                        <a class='btn btn-block btn-mcit' disabled>角色</a>
                    </th>
                    <th>
                        <a class='btn btn-block btn-mcit' disabled>公司名称</a>
                    </th>
                    <th width="28%">
                        <a class='btn btn-block btn-mcit' disabled>操作</a>
                    </th>
                </tr>
            </thead>
            <tbody>
                <empty name="user">
                    <td colspan="99" style="text-align:center" class="danger"> <strong><i class="fa fa-meh-o"></i>
                            &nbsp;&nbsp;当前条件下没有数据</strong> 
                    </td>
                    <else />
                    <volist name="user" id="data">
                        <if condition="$data.id eq $newid">
                            <tr class="danger">
                        <else/>
                            <tr>
                        </if>
                            <td><p class="mcit-table-p">{$data.id}</p></td>
                            <td><p class="mcit-table-p">{$data.fac_login_name}</p></td>
                            <td><p class="mcit-table-p">{$data.roleName}</p></td>
                            <td><p class="mcit-table-p">{$data.fac_name}</p></td>
                            <td>
                                <!--<a class="btn btn-sm btn-warning" href="__URL__/editUser/id/{$data.id}">-->
                                <a class="btn btn-sm btn-warning" href={$data.id|mcitUrl = ###,'edit_user1'}>
                                <i class="fa fa-edit"></i>
                                    &nbsp;修改账号
                                </a>
                                <a class="btn btn-sm btn-primary deleteBtn" href="#confirmDelete" data-target="#confirmDelete" data-toggle="modal" data-id='{$data.id}'><i class="fa fa-trash-o"></i>
                                    &nbsp;站点分配</a>
                                <a class="btn btn-sm btn-danger del_role" data-id="{$data.id}">
                                    <i class="fa fa-trash-o"></i>
                                    &nbsp;删除账号
                                </a>
                            </td>
                        </tr>
                    </volist>
                </empty>

                <tr>
                    <td colspan="99" style="text-align:center">
                        <ul class="pagination">{$pageView}</ul>
                    </td>
                </tr>
            </tbody>
        </table>

    </div>

</div>
<!-- 删除分类 -->
<div id="confirmDelete" class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 id="myModalLabel">站点分配</h4>
            </div>
            <div class="modal-body">
                <ul class="nav nav-tabs" id="myTab">
                    <li class="active"><a href="#home">未分配</a></li>
                    <li><a href="#profile">所属</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="home">

                        <table  class="table table-bordered table-striped table-mcit" style="font-size: 10px">
                            <thead>
                            <tr>
                                <th><button class='btn btn-block btn-mcit'>选择</button></th>
                                <th ><button class='btn btn-block btn-mcit' type='button'>站点ID</button></th>
                                <th><button class='btn btn-block btn-mcit' type='button'>名称</button></th>
                                <th><button class='btn btn-block btn-mcit' type='button'>所在地</button></th>
                            </tr>
                            </thead>
                            <tbody class="weifenpei">

                            </tbody>
                        </table>
                        <div class="modal-footer">
                            <a class="btn btn-primary" id="confirmDeleteBtn">确定分配</a>
                        </div>
                    </div>
                    <div class="tab-pane" id="profile">
                        <table  class="table table-bordered table-striped table-mcit" style="font-size: 10px">
                            <thead>
                            <tr>
                                <th><button class='btn btn-block btn-mcit'>选择</button></th>
                                <th ><button class='btn btn-block btn-mcit' type='button'>站点ID</button></th>
                                <th><button class='btn btn-block btn-mcit' type='button'>名称</button></th>
                                <th><button class='btn btn-block btn-mcit' type='button'>所在地</button></th>
                            </tr>
                            </thead>
                            <tbody class="yifenpei">

                            </tbody>
                        </table>
                        <div class="modal-footer">
                            <a class="btn btn-primary" id="confirmDeleteBtns">取消分配</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="hide" id="cache">1</div>
</div>
<import file="js.jquery#chained" />
<script type="text/javascript">
    $(".del_role").click(function(){
        var id = $(this).attr('data-id');
        alertify.confirm("确定要删除此账号？", function (e) {
            if (e) {
                $.ajax({
                    type: "POST",
                    url:  '{:U("Set/delUser")}',
                    data: {id:id},
                    dataType: "json",
                    success: function(data){
                        if(data.state==100){
                            alertify.success(data.msg);
                            location.reload(true);
                        }else{
                            alertify.error(data.msg);
                        }
                    }
                });
            } else {
                alertify.error("取消操作！");
            }
        }, "mcit_default");
    });
    $("#add_role").ajaxForm({
        dataType:'json',
        clearForm:true,
        beforeSubmit:function(){
            if($("#name").val()==''){
                alertify.error("请填写要添加的角色名称");
                return false;
            }
            return true
        },
        success:function(data){
            if(data.state==100){
                alertify.success(data.msg);
                location.href = data.url;
            }else{
                alertify.error(data.msg);
            }
        }
    });

    $(".deleteBtn").click(function(){
        var id = $(this).attr('data-id');
        $("#cache").text(id);
        $.ajax({
            type:'get',
            url:'{:U("Set/site")}',
            data:{nid:id},
            dataType:'json',
            success:function(data){
//                alert(data);exit;
                var str     = '';
                var strs    = '';
                var string  = '';
                var strings = '';
                $.each(data,function(name,value) {
//                    alert(value.name);
                    if(value.yy_user_id == value.nid){
                        str = '<tr class="listss" align="center"><td><input type="checkbox"  value="'+value.id+'"/></td> <td>'+value.id+'</td><td>'+value.name+'</td><td>'+value.fullname+'</td></tr>';
                        string  += str;
                    }else if(value.yy_user_id == value.pid){
                        strs = '<tr class="lists" align="center"><td><input type="checkbox"  value="'+value.id+'"/></td> <td>'+value.id+'</td><td>'+value.name+'</td><td>'+value.fullname+'</td></tr>';
                        strings += strs;
                    }
                });
                $(".yifenpei").html(string+'<tr><td colspan="99"><input type="button" value="全选"   class="btn" onclick="selectAlls()">  <input type="button" value="全不选" class="btn" onclick="unSelects()"></td></tr>');
                $(".weifenpei").html(strings+'<tr><td colspan="99"><input type="button" value="全选"   class="btn" onclick="selectAll()">  <input type="button" value="全不选" class="btn" onclick="unSelect()"></td></tr>');
                //location.reload();
            }
        });
    });
</script>
<script>
    $('#myTab a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    });
    //全选
    function selectAll() {
        $(".lists :checkbox").prop("checked", true);
    }
    //全不选
   function unSelect() {
        $(".lists :checkbox").prop("checked", false);
    }

    //全选(已分配)
    function selectAlls() {
        $(".listss :checkbox").prop("checked", true);
    }
    //全不选
    function unSelects() {
        $(".listss :checkbox").prop("checked", false);
    }
    //确定分配（批量）
    $("#confirmDeleteBtn").click(function(){
        var valArray   = new Array;
        var yy_user_id = $("#cache").text();
        $("input[type='checkbox']:checked").prop("checked", function(i) {
            valArray[i] = $(this).val();
        });
        var values = valArray.join(',');
        if(values == ''){
            alert("请选择要处理的数据!");
        }else{
            alertify.confirm("确定分配吗？", function (e) {
                if (e) {
                    $.ajax({
                        type: "POST",
                        url:  '{:U("Set/confirm")}',
                        data: {ids:values,yy_user_id:yy_user_id},
                        dataType: "json",
                        success: function(data){
                            if(data.state==100){
                                alert(data.msg);
                            }else{
                                alert(data.msg);
                            }
                            location.reload();
                        }
                    });
                } else {
                    alertify.error("取消操作！");
                }
            }, "mcit_default");
        }
    });
    //取消分配（批量）
    $("#confirmDeleteBtns").click(function(){
        var valArray   = new Array;
        $("input[type='checkbox']:checked").prop("checked", function(i) {
            valArray[i] = $(this).val();
        });
        var values = valArray.join(',');
        if(values == ''){
            alert("请选择要处理的数据!");
        }else{
            alertify.confirm("确定分配吗？", function (e) {
                if (e) {
                    $.ajax({
                        type: "POST",
                        url:  '{:U("Set/cancel")}',
                        data: {ids:values},
                        dataType: "json",
                        success: function(data){
                            if(data.state==100){
                                alert(data.msg);
                            }else{
                                alert(data.msg);
                            }
                            location.reload();
                        }
                    });
                } else {
                    alertify.error("取消操作！");
                }
            }, "mcit_default");
        }
    });
</script>